﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProduceBasicData.Api.Application.Command.RBAC.Department;
using ProduceBasicData.Api.Application.Command.RBAC.User;
using ProduceBasicData.Api.DTO.RBACDto;
using ProduceBasicData.ErrorCode;

namespace ProduceBasicData.Api.Controllers.RBAC
{
    /// <summary>
    /// 用户控制器
    /// </summary>
    /// <remarks>
    /// 构造函数
    /// </remarks>
    /// <param name="mediator"></param>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UsersController(IMediator mediator) : ControllerBase
    {
        private readonly IMediator _mediator = mediator;

        /// <summary>
        /// 创建用户
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateUser(CreateUserCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<UsersDto>> GetUserList([FromQuery] GetUserCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 更新用户
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateUser(UpdateUserCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteUser(DeleteUserCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 用户批量删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteRangeUser(DeleteRangeUserCommand command)
        {
            return await _mediator.Send(command);
        }
    }
}
